<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../common/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<sfa:mainTitle></sfa:mainTitle>
		<%@ include file="../../../common/meta.jsp"%>
		<link rel="stylesheet" href="${path }/css/affixUpload.css"
			type="text/css"></link>
		<script type="text/javascript"
			src="../../../script/lhgdialog/lhgdialog.min.js">
</script>
		<script type="text/javascript" src="${path}/script/affixUpload.js">
</script>
		<script type="text/javascript">
var trianTpye = '';
$(function() {
	//设置表单验证
	$("#trainerGrade").hide();
	var addForm = $("#addForm").validate( {
		rules : {
			trainerName : {
				required : true,
				rangelength : [ 2, 20 ]
			},
			goodAtItem : {
				required : true,
				rangelength : [ 2, 16 ]

			}
		}
	});
	//提交
	$("#btn_submit")
			.click(
					function() {
					 
				var branchId = $("#branchId").val();
				var trainerName = $("#trainerName").val();
				var trainerLevel = $("#trainerLevel").val();
				var trainerGrade = $("#trainerGrade").val();
				var goodAtItem = $("#goodAtItem").val();		
				var Grade='';
				if(trianTpye == 'TRAINERTYPE_A'){
					Grade =trainerLevel;
					}
				if(trianTpye == 'TRAINERTYPE_B'){	
					Grade =trainerGrade;
					}	
				if(trainerName==''){
						art.dialog( {
					icon : "error",
					content : "讲师姓名称不能为空!",
					lock : true,
					ok : true
					});
				return false;
				}
				if(goodAtItem==''){
						art.dialog( {
					icon : "error",
					content : "擅长课程不能为空!",
					lock : true,
					ok : true
					});
				return false;
				}
			var data ={
				branchId:branchId,
				trainerName:trainerName,
				Grade:Grade,
				goodAtItem:goodAtItem,
				trianTpye:trianTpye
			};			
			$.ajax({
				url : "${path}/productandtrain/lecturer/index/addtrainers",
				type : "POST",
				timeout : 10000,
				data : data,
				success :function(result) {
					if (result == "true") {
						art.dialog({
							icon : "succeed",
							content : "新增成功",
							lock : true,
							ok : function() {
							window.location.href = "${path}/productandtrain/lecturer/index/trainer";
								}
						});
					} else {
						art.dialog({
							icon : "error",
							content : "新增失败",
							lock : true,
							ok : true
						});
					}
			} 
		});
 	
		});
});
function opendialog() {
	$.dialog( {
		title : '外勤关联',
		lock : true,
		background : '#FFF',
		opacity : 0.1,
		max : false,
		min : false,
		width : '650px',
		height : '550px',
		content : 'url:${path}/productandtrain/lecturer/index/operation'
	});
}

function addProducts(trainerName,brachid,triantype) {
var list = $.dialog.list;
	for ( var i in list) {
		list[i].close();
	}
	var trainerName=trainerName;
	var brachid=brachid;
	var  type = triantype; 
	//alert(type);
	trianTpye = type;
	if(type == 'TRAINERTYPE_B'){
		$("#trainerGrade").show();
		$("#trainerLevel").hide();
	} else{
		$("#trainerGrade").hide();
		$("#trainerLevel").show();
	} 
	document.getElementById("trainerName").value = trainerName;
	document.getElementById("branchId").value = brachid;
	$("#trainerName").attr("readonly","true");
}

function delItem(obj) {
	$(obj).parent().remove();
}
</script>
	</head>
	<body id="master">

		<sfa:mainHeader></sfa:mainHeader>
		<div class="webpart3 contentarea">
			<div class="webpart-head">
				<div class="webpart-head-item">
					新建讲师
				</div>
			</div>
			<div class="webpart-main">
				<div class="webpart-main-item" style="padding: 15px;">
					<form id="addForm">
						<div class="d_formitem">
							<table cellspacing="0" cellpadding="0" class="formitem">
								<tr>
									<td width="20%">
										<span>所属机构：</span>
									</td>
									<td>
										<select class="input-txt" name="branchId" id="branchId">
											<c:forEach items="${BranchList}" var="branch">
												<option value="${branch.branchId}">
													${branch.branchName}
												</option>
											</c:forEach>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										<span>讲师姓名：</span>
									</td>
									<td>
										<input type="text" id="trainerName" name="trainerName"
											class="input-txt" maxlength="20" tyle="width: 120px;" />
										<input type="button" id="" tabindex="5" class="linkbtn2"
											value="选择人员" onclick="opendialog()">

									</td>
								</tr>
								<tr>
									<td>
										<span>职&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;级：</span>
									</td>
									<td>

										<sfa:dic showType="select" kindNo="TRAINERLEVEL"
											attr="class='selectbox'" name="trainerLevel"
											id="trainerLevel"></sfa:dic>

										<sfa:dic showType="select" kindNo="TRAINERGRADE"
											attr="class='selectbox'" name="trainerGrade"
											id="trainerGrade"></sfa:dic>

									</td>
								</tr>
								<tr>
									<td>
										<span>擅长课程：</span>
									</td>
									<td>
										<input type="text" class="input-txt" id="goodAtItem"
											name="goodAtItem" maxlength="16" tyle="width: 120px;" />
										</div>
									</td>
								</tr>

								<tr>
									<td>
									</td>
									<td>
										<input type="button" id="btn_submit" tabindex="5"
											class="linkbtn2" value="提交">
										&nbsp;&nbsp;
										<input type="button" id="btn_submit" tabindex="5"
											class="linkbtn2" value="返回"
											onclick="location.href='${path}/productandtrain/lecturer/index/trainer';">
									</td>
								</tr>
							</table>
						</div>
					</form>
				</div>
				<div class="webpart-foot">
					<div class="webpart-foot-item">
					</div>
				</div>
			</div>
		</div>
		<sfa:mainFooter></sfa:mainFooter>
	</body>
</html>